package d2p

import (
	"encoding/binary"
	"hy_808/protocol/jtt808"
)

// 终端通用应答0x0001
type DeviceAnswer struct {
	jtt808.Jtt808
}

func (this *DeviceAnswer) SetHead(bodyLen int) {
	this.Head.SetId(jtt808.DeviceAnswerId)
	this.Head.SetAttribute(int16(bodyLen), 0, 0)

}

func GenAnswer(serialNo, result int) *DeviceAnswer {
	da := &DeviceAnswer{}
	var serialNoBytes, answerIdBytes []byte
	binary.BigEndian.PutUint16(serialNoBytes, uint16(serialNo))
	binary.BigEndian.PutUint16(answerIdBytes, jtt808.PlatformAnswerId)
	var resultByte byte
	body := append(append(serialNoBytes, answerIdBytes...), resultByte)
	da.SetHead(len(body))
	da.SetBody(body)
	return da
}
